home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PASCALL / SHAPES / BLEEP.PAS next >
Pascal/Delphi Source File  |  1993-08-30  |  6KB  |  231 lines

  1. program Bleep;
  2. uses
  3.    Crt,Graph,Objects,Polygony;
  4.  
  5. procedure GetNum(a:integer; var n:integer);
  6. var
  7.    bin:integer;
  8. begin
  9.    n:=0;
  10.    if paramcount>=a then
  11.    begin
  12.       val(paramstr(a),n,bin);
  13.    end
  14. end;
  15.  
  16. const
  17.    acVacnt=    0;
  18.    acReNew=    10;
  19.    acCycle=    20;
  20. type
  21.    PBalls=^TBalls;
  22.    TBalls=object(TObject)
  23.       Collection                                   :     PCollection;
  24.       Count                                        ,
  25.       Number                                       ,
  26.       shp                                          ,
  27.       At                                           ,
  28.       Cnt                                          ,
  29.       Change                                       :     Integer;
  30.       Action                                       :     Byte;
  31.     constructor Init(N:Integer;shpe:integer);
  32.       procedure Initballs(var N:Integer);
  33.       procedure Cycle;
  34.       procedure Run;
  35.       procedure ReNew;
  36.       procedure Doer;
  37.      destructor Done;                                    virtual;
  38.    end;
  39. constructor TBalls.Init(N:Integer; shpe:integer);
  40. begin
  41.    inherited Init;
  42.    New(Collection,Init(N,0));
  43.    shp:=shpe;
  44.    Number:=N;
  45.    Initballs(Number);
  46.    change:=100;
  47. end;
  48. procedure   TBalls.InitBalls(var N:Integer);
  49. var
  50.    a: integer;
  51.    procedure NewDot;
  52.    begin
  53.       if maxavail>176 then
  54.       Collection^.Insert(New(PDot ,Init(((Random(GetMaxy)+1) div 8),random(getmaxcolor)+1,random(4),random(2))));
  55.    end;
  56.    procedure NewBall;
  57.    begin
  58.       if maxavail>176 then
  59.       Collection^.Insert(New(PBall,Init(((Random(GetMaxy)+1) div 8),random(getmaxcolor)+1,random(4),random(2))));
  60.    end;
  61.    procedure NewBox;
  62.    begin
  63.       if maxavail>176 then
  64.       Collection^.Insert(New(PBox ,Init(((Random(GetMaxy)+1) div 8),random(getmaxcolor)+1,random(4),random(2))));
  65.    end;
  66. begin
  67.    for a:=1 to N do
  68.    begin
  69.       if maxavail<=176 then
  70.       begin
  71.          N:=a-1;
  72.          Exit;
  73.       end;
  74.       case shp of
  75.          0: NewDot;
  76.          1: NewBall;
  77.          2: NewBox;
  78.          3: case random(3) of
  79.                0: NewDot;
  80.                1: NewBall;
  81.                2: NewBox;
  82.             end;
  83.       end
  84.    end;
  85. end;
  86. procedure   TBalls.ReNew;
  87. begin
  88.    count:=0;
  89.    change:=random(1000)+1;
  90.    if Action<>AcReNew then At:=0;
  91.    Action:=acReNew;
  92.    if (At>-1) and (At<Number) then
  93.       With PDot(Collection^.At(At))^ do
  94.       begin
  95.          ReNew;
  96.          Doer;
  97.       end;
  98.    Inc(At);
  99.    if At=Number then Action:=acVacnt;
  100. end;
  101. procedure   TBalls.Doer;
  102. begin
  103.    case Action of
  104.       acVacnt: begin
  105.                   if count>=change then ReNew;
  106.                   Cycle;
  107.                   Inc(Count);
  108.                end;
  109.       acCycle: Cycle;
  110.       acReNew: ReNew;
  111.    end;
  112. end;
  113. procedure   TBalls.Cycle;
  114. begin
  115.    if Action<>acCycle then At:=0;
  116.    Action:=acCycle;
  117.    if (At>-1) and (At<Number) then PDot(Collection^.At(At))^.Doer;
  118.    Inc(At);
  119.    if At=Number then Action:=acVacnt;
  120. end;
  121. procedure   TBalls.Run;
  122. begin
  123.    repeat
  124.       Doer;
  125.    until keypressed;
  126. end;
  127. destructor  TBalls.Done;
  128. begin
  129.    if Collection<>nil then Dispose(Collection,Done);
  130.    inherited Done;
  131. end;
  132.  
  133. type
  134.    TProg=object(TObject)
  135.       Using                                        :     PBalls;
  136.       shp                                          ,
  137.       Greater                                      :     Integer;
  138.     constructor Init(shpe:integer);
  139.       procedure Run;                                     virtual;
  140.      destructor Done;                                    virtual;
  141.    end;
  142. constructor TProg.Init(shpe:integer);
  143. var
  144.    gd,gm:integer;
  145. begin
  146.    gd:=vga;  gm:=vgahi;
  147.    InitGraph(gd,gm,'c:\tp\bgi');
  148.  
  149.    inherited Init;
  150.    GetNum(2,Greater);
  151.    if Greater<=0 then Greater:=5;
  152.    shp:=shpe;
  153.    randomize;
  154.    New(Using,Init(Greater,shp));
  155. end;
  156. procedure   TProg.Run;
  157. var
  158.    s:boolean;
  159. begin
  160.    s:=false;
  161.    repeat
  162.       Using^.Run;
  163.       case readkey of
  164.          #32: begin
  165.                  Dispose(Using,Done);
  166.                  New(Using,Init(Greater,shp));
  167.               end;
  168.          #13: Using^.ReNew;
  169.          #27: s:=True;
  170.       end;
  171.    until s;
  172. end;
  173. destructor  TProg.Done;
  174. begin
  175.    if Using<>nil then Dispose(Using,Done);
  176.    inherited Done;
  177.    RestoreCrtMode;
  178. end;
  179.  
  180. var
  181.    A:TProg;
  182.    t:integer;
  183. begin
  184.    if pos('?',paramstr(1)+paramstr(2))=0 then
  185.    begin
  186.       GetNum(1,t);
  187.       Write('Bleep v1.5 using ');
  188.       case t of
  189.          0: Write('pixel dots');
  190.          1: Write('circles');
  191.          2: Write('boxes');
  192.          3: Write('random polygons');
  193.       end;
  194.       GetNum(2,t);
  195.       if t<=0 then t:=5;
  196.       Writeln(', at ',t,' max counts.');
  197.       Writeln;
  198.       Writeln('Press Any Key to Continue');
  199.       readln;
  200.       GetNum(1,t);
  201.       A.Init(t);
  202.       A.Run;
  203.       A.Done;
  204.       Writeln('Thanks for using Bleep v1.5');
  205.    end
  206.    else begin
  207.       Writeln;
  208.       Writeln('Bleep v1.5');
  209.       Writeln('COPRIGHT 1993 Fernando Padilla.  ALL RIGHTS RESERVED.');
  210.       Writeln('Will grant Public Domain use on program, but not on code.');
  211.       Writeln;
  212.       Writeln('Syntax: BLEEP # #######');
  213.       Writeln('              ^    ^');
  214.       Writeln(' Polygon Code-/    |');
  215.       Writeln(' Polygon Count-----/');
  216.       Writeln;
  217.       Writeln;
  218.       Writeln(' Polygon Code:');
  219.       Writeln('        0 - pixel dots');
  220.       Writeln('        1 - circles-------- sizes change during run time');
  221.       Writeln('        2 - boxes-------/');
  222.       Writeln('        3 - random polygons (from above)');
  223.       Writeln;
  224.       Writeln(' Polygon Count:');
  225.       Writeln('        Can be ANY number between 1 to 32767, but the high limit of polygons');
  226.       Writeln('  depends of memory available.  So, if 32767 (or any number), Bleep will use');
  227.       Writeln('  as many polygons as possible, with the memory available.  Also, if a value');
  228.       Writeln('  of less than of equal to 0, the value of 5 will be used.');
  229.       Writeln;
  230.    end;
  231. end.